package com.security.door.core.mybatis;

import com.google.common.collect.Lists;
import com.security.door.core.constants.Constants;

import java.io.Serializable;
import java.util.List;


/**
 * 功能描述: 分页对象，包含当前页数据及分页信息如总记录数
 *
 * @author jq
 * @date 2018/3/6
 */
public class Page<T> implements Serializable {

    private static final long serialVersionUID = 5859907455479273251L;

    /**
     * 当前页码，从1开始记数
     */
    private long pageIndex = Constants.DEFAULT_PAGE_INDEX;
    /**
     * 每页的记录数
     */
    private int pageSize = Constants.DEFAULT_PAGE_SIZE;

    private List<T> data = Lists.newArrayList();

    /**
     * 总记录数
     */
    private long resultCount;

    public Page() {
    }

    public Page(int pageSize, long pageIndex, List<T> data, long resultCount) {
        this.pageSize = pageSize;
        this.pageIndex = pageIndex;
        this.data = data;
        this.resultCount = resultCount;
    }

    /**
     *
     * @return 总页数
     */
    public long getPageCount() {
        if (resultCount % pageSize == 0) {
            return resultCount / pageSize;
        }
        else {
            return resultCount / pageSize + 1;
        }
    }

    public long getPageIndex() {
        return pageIndex;
    }

    public void setPageIndex(long pageIndex) {
        this.pageIndex = pageIndex;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }

    public long getResultCount() {
        return resultCount;
    }

    public void setResultCount(long resultCount) {
        this.resultCount = resultCount;
    }
}